<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<jsp:include page="../../common/header.jsp" />
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<script type="text/javascript">
//分页
function toListPage(pageIndex){
	$("#list_form").attr("action","<%=request.getContextPath()%>/sso/company_user/list");
	$("#iDisplayStart").val(pageIndex);
	$("#list_form").submit();
}

//新增或者编辑
function toEditPage(id){
	$("#list_form").attr("action","<%=request.getContextPath()%>/sso/company_user/form");
	$("#hiddenId").val(id);
	$("#list_form").submit();
}

//跳转角色页面
function toRolePage(id,username){
	$("#list_form").attr("action","<%=request.getContextPath() %>/sys/company_user/role");
	$("#usernameId").val(username);
	$("#hiddenId").val(id);
	$("#list_form").submit();
}


//删除
function delCompanyUser(id,username){
	bootbox.dialog({
		message : "<spring:message code="sure you want to delete"></spring:message>"+username+"<spring:message code="what"></spring:message>",
		title : "删除企业用户",
		buttons : {
			confirm : {
				label : '<spring:message code="sure to delete"></spring:message>',
				className : "btn red btn-ok",
				callback : function() {
					$.ajax({
						type : "GET",
						url : "<%=request.getContextPath()%>/sso/company_user/del?id="+id,
						dataType : 'text',
						async : false,
						success : function(data) {
							if(data=="success"){
								noty({layout: 'top',text: "删除成功！",type: 'success', timeout: 2000 });
								setTimeout(function(){window.location.reload();}, 1000);
							}else{
								noty({layout: 'top',text: "删除失败！",type: 'error', timeout: 2000 });
							}
						},
						error : function(data, status) {
							noty({layout: 'top',text: "<spring:message code="error"></spring:message>！",type: 'error', timeout: 2000 });
						}
					});
				}
			},
			cancel : {
				label : "<spring:message code="cancel"></spring:message>",
				className : "btn btn-danger"
			}
		}
	});
}

</script>
</head>
<body class="page-header-fixed page-full-width">

		<form id="list_form" action="<%=request.getContextPath()%>/sso/company_user/list" method="post">
			<input type="hidden" name="id" id="hiddenId"></input> 
			<input type="hidden" name="username" id="usernameId"></input> 
	    <input type="hidden" name="iDisplayStart" id="iDisplayStart" value=${list.currentPage } />
			<div class="page-content">
				<div class="container-fluid">
					<div class="row-fluid">

						<div class="span12">


							<h3 class="page-title">

								<!--系统用户管理 <small>欢迎您，admin!</small> -->

							</h3>

							<ul class="breadcrumb">

								<li><i class="icon-home"></i> <a href="index.html">Home</a>

									<i class="icon-angle-right"></i></li>

								<li><a href="#">单点登录系统</a> <i class="icon-angle-right"></i>

								</li>

								<li><a href="#">企业用户</a></li>

							</ul>



						</div>

					</div>
					
					
					<div class="row-fluid">
					<div class="portlet-body">
						<div class="clearfix">

								<p class="pull-left">

									<a href="#" onclick="toEditPage(null);" class="btn blue">

										新增企业用户 <i class="icon-plus"></i>

									</a>
								</p>

								<div class="btn-group pull-right">

									<button class="btn dropdown-toggle" data-toggle="dropdown">
										Tools <i class="icon-angle-down"></i>

									</button>

									<ul class="dropdown-menu pull-right">

										<li><a href="#">Print</a></li>

										<li><a href="#">Save as PDF</a></li>

										<li><a href="#">Export to Excel</a></li>

									</ul>

								</div>

							</div>

							<div class="control-group">
								<div class="controls">
									企业编号:<select tabindex="1"
										data-placeholder="Choose a companyCode" class="span2 m-wrap"
										name="searchValue">
										<option value=""></option>
										<c:forEach var="company" items="${company_list}">
											<option
												<c:if test="${searchValue==company.companyCode}">selected="selected"</c:if>
												value="${company.companyCode}">${company.companyCode}</option>
										</c:forEach>
									</select>
									<button class="btn red">查询</button>
								</div>
							</div>
							
								<table class="table table-striped table-bordered table-hover"
								id="user_grid">
								<thead>
									<tr>
										<th>用户名</th>
										<th>邮箱</th>
										<th>电话</th>
										<th>创建时间</th>
										<th>创建人</th>
										<th>企业用户编号</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<c:forEach items="${list.resultList}" var="item"
										varStatus="status">
										<tr class="odd gradeX">
											<td>${item.username }</td>
											<td>${item.email }</td>
											<td>${item.phone }</td>
											<td>${item.createTime }</td>
											<td>${item.createUser }</td>
											<td>${item.companyCode }</td>
											<td><a href="#"
												onclick="toEditPage(${item.oauthUserId});"
												class="btn mini blue"><spring:message
														code="btn.common.edit"></spring:message></a> <a
												onclick="delCompanyUser(${item.oauthUserId},'${item.username }');"
												href="#" class="btn mini red"><spring:message
														code="btn.common.delete"></spring:message></a>
														<a onclick="toRolePage(${item.oauthUserId},'${item.username}')" href="#"  class="btn mini blue" ><spring:message
																code="role"></spring:message></a>
														</td>

										</tr>
									</c:forEach>
								</tbody>

							</table>
							
							<!-- 分页 -->
							<c:if test="${list.totalPages>1}">
								<div class="pagination" style="float: right">
									<ul>
										<li><a href="javascript:void();">总数：${list.totalRows}</a></li>
										<li
											<c:if test="${list.currentPage==1}">class="disabled"</c:if>>
											<c:if test="${list.currentPage>1}">
												<a href="javascript:toListPage(${list.currentPage-1});">上一页</a>
											</c:if> <c:if test="${list.currentPage==1}">
												<a href="#">上一页</a>
											</c:if>
										</li>
										<c:forEach begin="1" end="${list.totalPages}" var="item">
											<c:if
												test="${item < 4 || item==list.currentPage || item==list.currentPage+1 || item==list.currentPage+2 || item + 3 > list.totalPages }">
												<li
													<c:if test="${list.currentPage==item }">class="active"</c:if>><a
													href="javascript:toListPage(${item});">${item}</a></li>
											</c:if>
										</c:forEach>
										<li
											<c:if test="${list.currentPage==list.totalPages}">class="disabled"</c:if>>
											<c:if test="${list.currentPage==list.totalPages}">
												<a href="#">下一页 </a>
											</c:if> <c:if test="${list.currentPage!=list.totalPages}">
												<a href="javascript:toListPage(${list.currentPage+1})">下一页
												</a>
											</c:if>
										</li>
									</ul>
								</div>
							</c:if>
					
					</div>
					
					</div>

				</div>
			</div>
		</form>
</body>
</html>